package Layouts 
{
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.events.*;
	import flash.text.*;
	
	public class NextLevelMenu extends Sprite 
	{
		[Embed(source="../Resources/Texts/kidfont.ttf", fontName = "Kidfont",
		fontStyle = "normal" ,fontWeight = "bold", embedAsCFF= "false")]
		private static var font:Class;
		private var text_format1:TextFormat;
		private var text_format2:TextFormat;
		private var message:TextField;
		private var nextbutton_label:TextField;
		
		private var par:Main;
		
		[Embed(source = "../Resources/Images/Entities/Ardilla_Logo.png")]
		private var logo:Class;
		
		private var W:uint;
		private var H:uint;
		
		private var bg:Sprite = new Sprite();
		private var imgcont:Sprite = new Sprite();
		private var msgcont:Sprite = new Sprite();
		private var nextbutton:Sprite = new Sprite();
		
		private var save_level:uint;
		
		public function NextLevelMenu(parent:Main):void	{
			addEventListener(Event.ADDED_TO_STAGE, init);
			par = parent;
			save_level = par.screen_manager.game_files.data.save_level;
		}
		
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			W = stage.stageWidth;
			H = stage.stageHeight;
			
			bg.graphics.clear();
			bg.graphics.beginFill(0xFCF089);
			bg.graphics.drawRect(0 , 0, W, H);
			bg.graphics.endFill();
			addChild(bg);
			
			imgcont.graphics.clear();
			imgcont.graphics.beginFill(0xC99837);
			imgcont.graphics.drawRoundRect(0, 0, W / 3, W / 3, W/9);
			imgcont.graphics.endFill();
			addChild(imgcont);
			imgcont.x = W / 12,
			imgcont.y = W / 9;
			
			var img:Bitmap = new logo();
			imgcont.addChild(img);
			img.scaleX = 0.8;
			img.scaleY = 0.8;
			img.x = imgcont.width / 2 - img.width / 2;
			img.y = imgcont.height / 2 - img.height / 2;
			
			msgcont.graphics.clear();
			msgcont.graphics.beginFill(0xC99837);
			msgcont.graphics.drawRoundRect(0, 0, W * 5 / 12, W * 2/ 9, W /9);
			msgcont.graphics.endFill();
			addChild(msgcont);
			msgcont.x = W / 2,
			msgcont.y = W * 3 / 18;
			
			nextbutton.graphics.clear();
			nextbutton.graphics.beginFill(0xC99837);
			nextbutton.graphics.drawRoundRect(0, 0, W * 2/3, H / 8, H / 16);
			nextbutton.graphics.endFill();
			addChild(nextbutton);
			nextbutton.x = W / 6;
			nextbutton.y = W * 4 / 9 + (H - W * 4 / 9) / 2 - H / 16;
			nextbutton.buttonMode = true;
			nextbutton.useHandCursor = true;
			nextbutton.addEventListener(MouseEvent.CLICK, next_click);
			
			text_format1 = new TextFormat();
			text_format1.font = "Kidfont";
			text_format1.size = 50;
			
			text_format2 = new TextFormat();
			text_format2.font = "Kidfont";
			text_format2.size = 30;
			
			nextbutton_label = new TextField();
			nextbutton_label.embedFonts= true;
			nextbutton_label.defaultTextFormat = text_format1;
			nextbutton_label.selectable = false;
			nextbutton_label.autoSize = TextFieldAutoSize.LEFT;
			nextbutton_label.text = "Siguiente Nivel: " + (save_level + 1).toString();
			nextbutton.addChild(nextbutton_label)
			nextbutton_label.x = nextbutton.width/2 - nextbutton_label.textWidth/2;
			nextbutton_label.y = nextbutton.height / 2 - nextbutton_label.textHeight / 2;
			
			message = new TextField();
			message.embedFonts= true;
			message.defaultTextFormat = text_format2;
			message.selectable = false;
			message.autoSize = TextFieldAutoSize.LEFT;
			message.text = "Bien Hecho! Ganaste el nivel " + save_level.toString() + "!";
			msgcont.addChild(message)
			message.x = msgcont.width/2 - message.textWidth/2;
			message.y = msgcont.height / 2 - message.textHeight / 2;
			
		}
		
		private function next_click(e:MouseEvent):void {
			removeEventListener(MouseEvent.CLICK, next_click);
			par.screen_manager.goToScreen("Game");
			par.screen_manager.game_files.data.save_level = save_level + 1;
		}
	}

}